﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class First : Ship
{
    public GameObject m_AdditionalWeaponSlotLeft;
    public GameObject m_AdditionalWeaponSlotRight;
    public GameObject AdditionalEngine1;
    public GameObject AdditionalEngine2;
    public GameObject AdditionalEngine3;
    public GameObject AdditionalEngine4;

    public GameObject WingLeft;
    public GameObject WingRight;
    bool m_IsOpen = false;
    float m_WingAngle=0;

    float m_DurationTimeCount = 0;
    public float m_DurationTimeMax = 12;
    float m_VelocityIncrement = 1.3f;
    protected new void Start()
    {
        base.Start();
    }

    // Update is called once per frame
    protected new void Update()
    {
        base.Update();
        if (!m_IsOpen && m_WingAngle == 0)
            return;

        if(m_IsOpen)
        {
            m_DurationTimeCount += Time.deltaTime;
            if(m_DurationTimeCount > m_DurationTimeMax)
            {
                m_DurationTimeCount = 0;
                m_IsOpen = false;
                VelocityMutiple -= m_VelocityIncrement;
            }
        }

        WingLeft.transform.localRotation = Quaternion.AngleAxis(-m_WingAngle, new Vector3(0, 0, 1));
        WingRight.transform.localRotation = Quaternion.AngleAxis(m_WingAngle, new Vector3(0, 0, 1));
        if(m_IsOpen)
        {
            m_WingAngle = Mathf.Clamp(m_WingAngle+(Time.deltaTime * 90), 0, 90);
        }
        else
        {
            m_WingAngle = Mathf.Clamp(m_WingAngle - (Time.deltaTime * 90), 0, 90);
        }
        if(m_WingAngle == 0)
        {
            AdditionalEngine1.SetActive(false);
            AdditionalEngine2.SetActive(false);
            AdditionalEngine3.SetActive(false);
            AdditionalEngine4.SetActive(false);
            m_AdditionalWeaponSlotLeft.GetComponent<WeaponSlot>().m_FireLicense = false;
            m_AdditionalWeaponSlotRight.GetComponent<WeaponSlot>().m_FireLicense = false;
        }

    }
    public override bool LaunchSkill()
    {
        if (!base.LaunchSkill())
            return false;

        m_IsOpen = true;
        VelocityMutiple += m_VelocityIncrement;
        //RotationMutiple = 1.2f;
        AdditionalEngine1.SetActive(true);
        AdditionalEngine2.SetActive(true);
        AdditionalEngine3.SetActive(true);
        AdditionalEngine4.SetActive(true);
        m_AdditionalWeaponSlotLeft.GetComponent<WeaponSlot>().m_FireLicense = true;
        m_AdditionalWeaponSlotRight.GetComponent<WeaponSlot>().m_FireLicense = true;
        return true;
    }
    public override void OnChase()
    {
        if(SkillIsReady)
            LaunchSkill();
    }
    public override void OnFight()
    {
    }
    public override void OnRetreat()
    {
        if (SkillIsReady)
            LaunchSkill();
    }
}
